/*
 * EquilibriumSolver2.h
 *
 *  Created on: 26 Jul 2011
 *      Author: Allan
 */

#ifndef EQUILIBRIUMSOLVER2_H_
#define EQUILIBRIUMSOLVER2_H_

// C++ includes
#include <functional>
#include <tuple>
#include <vector>
using namespace std;

// Eigen includes
#include <Eigen/Core>
using namespace Eigen;

// GeoReact includes
#include <Core/EquilibriumConditions.h>
#include <Core/EquilibriumProblem2.h>
#include <Core/Multiphase.h>
#include <Core/ReactionSystem.h>
#include <Numerics/NewtonSolver.h>
#include <Utils/ConvergenceDiagnostics.h>

class EquilibriumSolver2 
{
public:
	EquilibriumSolver2();
	
	EquilibriumSolver2(const Multiphase& multiphase, const ReactionSystem& reactions);
	
	void Initialiaze(const Multiphase& multiphase, const ReactionSystem& reactions);
	
	void SetDecompositionAlgorithm(NewtonSolver::Decomposition decomposition);
	
	void SetConvergenceOptions(double tolerance, uint maxiterations);
	
	ConvergenceDiagnostics Solve(const EquilibriumConditions& econditions, double T, double P, VectorXd& n);
	
private:
	/// The multiphase instance
	Multiphase multiphase;
	
	/// The system of equilibrium-controlled reactions in the canonical representation
	ReactionSystem eReactions;
	
	/// The newton solver object used to solve the non-linear system of equations
	NewtonSolver newtonsolver;
	
	/// The stoichiometric matrix of the system of equilibrium-controlled reactions
	MatrixXd uei;
	
	/// The residual tolerance of the non-linear function vector
	double tolerance;
	
	/// The maximum number of iterations
	uint maxiterations;
};

#endif /* EQUILIBRIUMSOLVER2_H_ */
